<?php
include_once(_APP_PATH. "modules/controlls/controllers/params/params_field.php");
class ParamsFieldImage extends ParamsField{

	public function PreparePostData($fieldPostData)
	{
		$fieldPostData = preg_replace('#^' . preg_quote(_ROOT_URL) . '#is', '', urldecode($fieldPostData));
		
		$outValue = array();
		if (is_file(_ROOT_PATH . $fieldPostData))
		{
			$size = @getimagesize(_ROOT_PATH . $fieldPostData);
			if ($size[0] && $size[1])
			{
				$outValue = array('file' => $fieldPostData , 'width' => $size[0] , 'height' => $size[1]);
			}
		}
		
		return $outValue;
	}
	
	public function PrepareOutData($fieldData)
	{
		$fieldData = (array)$fieldData;
		$fieldData = array(
                                'file' => $fieldData['file'] ? _ROOT_URL. (string)$fieldData['file'] : '',
                                'width' => (int)$fieldData['width'],
								'height' => (int)$fieldData['height'],
		);
		
		return $fieldData;
	}	

}